package com.yzf.smsforward;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.yzf.pcsmsforward.R;
import com.yzf.smsforward.utils.Utils;

import java.util.ArrayList;
import java.util.List;

/**
 * 项目名称：SMSForward
 * 类描述：画中画串口适配器
 * 创建人：luohao
 * 创建时间：2021/6/8 11:12
 * 修改人：luohao
 * 修改时间：2021/6/8 11:12
 * 修改备注：
 */
public class MiniWindowAdapter extends BaseAdapter {
    private Context context;
    private int resource;
    private List<Sms> list;

    public MiniWindowAdapter(@NonNull Context context, int resource, List<Sms> list) {
        this.context = context;
        this.resource = resource;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        View view = LayoutInflater.from(context).inflate(resource, null);//实例化一个对象
        TextView mTV_time = view.findViewById(R.id.mTV_time);//获取该布局内的图片视图
        TextView mTV_phone_num = view.findViewById(R.id.mTV_phone_num);//获取该布局内的文本视图
        Sms sms = list.get(position);
        mTV_time.setText(Utils.stringToLongToDate(sms.getReceiveTime()));
        mTV_phone_num.setText(sms.getOriginatingAddress());
        return view;
    }
}
